package crudfx.control;
import crudfx.field.*;
import crudfx.util.*;
import crudfx.interop.*;
import crudfx.data.*;
import javax.swing.*;
//import java.awt.*;
import javafx.scene.paint.*;
/**
 * @profile desktop
 * @author Sergey Surikov
 */
public class ArtGridCell extends UIComponent,ArtGridCellValue{
    protected var jLabel:ArtGridLabel;
    public var icon:javax.swing.Icon on replace{jLabel.setIcon(icon);};
    public var text:String="" on replace{jLabel.setText(text);};
    public var leftToRight:Boolean=true on replace{
        if(leftToRight)
            jLabel.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT)
            else jLabel.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT );
        };
    /*init{
        jLabel=new JLabel(text);
        if(leftToRight)
            jLabel.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT)
            else jLabel.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT );
        jLabel.setVerticalAlignment(SwingConstants.TOP);
        jLabel.setIcon(icon);
        jLabel.setOpaque(false);
        }*/
    override public function highlight(s:String):Boolean{
        return false;
        }
    override public function gather():DataTree{
        var me:DataTree=DataTree{ name:"StandardLabel" };
        me.node("text").asString("").value=text;
        return me;
        }
    override public function change(value:String,isSelected:Boolean,row:Integer,column:Integer):Void{
      this.text=value;
      if(isSelected){
          jLabel.setForeground(new java.awt.Color(selectedColor.red,selectedColor.green,selectedColor.blue,selectedColor.opacity));
          jLabel.setBackground(new java.awt.Color(selectedBackground.red,selectedBackground.green,selectedBackground.blue,selectedBackground.opacity));
      }else{
          jLabel.setForeground(new java.awt.Color(color.red,color.green,color.blue,color.opacity));
          jLabel.setBackground(new java.awt.Color(background.red,background.green,background.blue,background.opacity));
          }
      }
    public var color:Color=Color.web("#000000") on replace{
        jLabel.setForeground(new java.awt.Color(color.red,color.green,color.blue,color.opacity));
        };
    public var background:Color=Color.web("#000000",0.01) on replace{
        jLabel.setBackground(new java.awt.Color(background.red,background.green,background.blue,background.opacity));
        };
    public var selectedColor:Color=Color.web("#ffffff");
    public var selectedBackground:Color=Color.web("#000000");
    public-init var bold:Boolean=false;
    public-init var italic:Boolean=false;
    public-init var serifs:Boolean=false;
    public-init var monospaced:Boolean=false;
    public-init var size:Number=9;
    init{
        //jLabel=new ArtGridLabel(text);
        var me=this;
        jLabel=ArtGridLabel{
            override public function change(value:String
                  ,isSelected:Boolean
                  ,row:Integer,column:Integer)
              :Void{
                me.change(value, isSelected, row, column);
              }
            };
        jLabel.setText(text);
        if(leftToRight)
            jLabel.setComponentOrientation(java.awt.ComponentOrientation.LEFT_TO_RIGHT)
            else jLabel.setComponentOrientation(java.awt.ComponentOrientation.RIGHT_TO_LEFT );
        jLabel.setVerticalAlignment(SwingConstants.TOP);
        jLabel.setIcon(icon);
        jLabel.setOpaque(false);

        jLabel.setForeground(new java.awt.Color(color.red,color.green,color.blue,color.opacity));
        jLabel.setBackground(new java.awt.Color(background.red,background.green,background.blue,background.opacity));
        var fn:String="SansSerif";
        if(monospaced)fn="Monospaced";
        if(serifs)fn="Serif";
        var fst:Integer=0;
        if(bold)fst=fst+java.awt.Font.BOLD;
        if(italic)fst=fst+java.awt.Font.ITALIC;
        var font:java.awt.Font=new java.awt.Font(fn,fst,size);
        jLabel.setFont(font);
        jLabel.setOpaque(true);
        }
    override public function getJComponent():JComponent{
        return jLabel;
        }
  }
